import type { Address } from './address'

export interface Order {
  orderId: number
  orderSn: string
  userId: number
  totalAmount: number
  payAmount: number
  status: number
  receiverName: string
  receiverPhone: string
  receiverAddress: string
  remark?: string
  createdAt: string
  updatedAt: string
  orderItems: OrderItem[]
  address?: Address
}

export interface OrderItem {
  itemId: number
  orderId: number
  shoeId: number
  productSku: string
  productName: string
  productImage: string
  quantity: number
  productPrice: number
  totalPrice: number
}

export interface OrderCreateRequest {
  addressId: number
  items: {
    productId: number
    quantity: number
    sku?: string
  }[]
  shippingMethod: string
  paymentMethod: string
  remark?: string
}

// 与后端 OrderController#createOrder 接口对齐的请求体结构
export interface CreateOrderPayload {
  order: {
    userId: number
    totalAmount: number
    payAmount: number
    receiverName: string
    receiverPhone: string
    receiverAddress: string
  }
  items: Array<{
    shoeId: number
    productSku: string
    productName: string
    productImage: string
    productPrice: number
    quantity: number
    totalPrice: number
  }>
}

export interface OrderQuery {
  status?: OrderStatus
  page?: number
  size?: number
  startDate?: string
  endDate?: string
}

export interface OrderStatusUpdateRequest {
  orderId: number
  status: OrderStatus
}

export interface OrderCancelRequest {
  orderId: number
  reason?: string
}

export type OrderStatus =
  | 'PENDING_PAYMENT'
  | 'PAID'
  | 'SHIPPED'
  | 'DELIVERED'
  | 'COMPLETED'
  | 'CANCELLED'
  | 'EXPIRED'
export type PaymentStatus = 'PENDING' | 'PAID' | 'REFUNDED'

export interface RefundRequest {
  orderId: number
  reason: string
  amount: number
}
